<%@page import="java.text.SimpleDateFormat"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="com.neiquan.backstage.common.util.SpringContextUtils"%>
<%@page import="com.neiquan.backstage.common.util.Sessions"%>
<%@page import="java.util.List"%>
<%@page import="com.neiquan.backstage.common.CommonService"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
ApplicationContext appCtx =  SpringContextUtils.getApplicationContext();
CommonService commonService = appCtx.getBean(CommonService.class);
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<meta charset="UTF-8">
	<title>申请工位</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=1.0" />
	<meta name="apple-mobile-web-app-capable" content="yes" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<link rel="stylesheet" href="css/main.css" />
	<link rel="stylesheet" href="css/base.css" />
	<link rel="stylesheet" href="js/time/css/normalize3.0.2.min.css" />
	<link rel="stylesheet" href="js/time/css/style.css" />
	<link href="js/time/css/mobiscroll.css" rel="stylesheet" />
	<link href="js/time/css/mobiscroll_date.css" rel="stylesheet" />
</head>
	<body bgcolor="#ededed">
		<section class="common_bg addr_wrap">
			<section  class="relative tc area-wrap">
				<label>我的工位</label>
			</section> 
			<section class="line addr_line"></section>
			<section class="mt">
				<table id='table1' class="addr_table" cellpadding="0" cellspacing="0">
				</table>
				<p class="tc">
					<span class="diamond">已选择的工位</span>
					<span class="diamond diamond_right">已被占用</span>
				</p>
				<section class="line"></section>
				<section class="common_bg">
					<section class="perfect pd">
						<p class="form-inpt-p">
							<label>租金</label>
							<input id="sumRental1" name="sumRental1" class="inpt" form="addrvisitorform" required name="peopleCount" type="text" readonly="readonly" placeholder="0" />(元/月)
						</p>
						<p class="form-inpt-p">
							<label class="vistor-instuct">租用开始时间</label>
      						<input type="text" name="startTime" id="startTime" required class="inpt project-type" value="<%=commonService.formatTimestamp(System.currentTimeMillis(),"yyyy-MM-dd")%>" placeholder="<%=commonService.formatTimestamp(System.currentTimeMillis(),"yyyy-MM-dd")%>" readonly="readonly"/>
						</p>
						<p class="form-inpt-p">
							<label class="vistor-instuct">租用结束时间</label>
							<input id="endTime" name="endTime" class="inpt" form="addrvisitorform" required name="peopleCount" type="text" pattern="\d" placeholder="0" readonly="readonly" />
						</p>
							<p class="tc">（结束时间与您第一批工位租用时间一致）</p>
					</section>
				</section>
				<section class="addr_sub pd">
					<input type="button" class="btn rent_submmit" onClick="applyStation()" value="申请工位">
				</section>
				<p class="tc">注：新申请工位，需要审核后才能生效</p>
				<section class="addr_sub pd">
				</section>
			</section>
		</section>
	<script src="js/jquery.min.js"></script>
	<script src="js/main.js"></script>
	<script src="js/responsive.js"></script>
	<script src="js/time/js/mobiscroll_date.js" charset="utf-8"></script> 
	<script src="js/time/js/mobiscroll.js"></script> 
	<script type="text/javascript">
	//设置租用结束时间
	$(function(){
		$("#endTime").val('${param.endTime}');
	});
	var monthMumber2=0;
	var sumRental=0;
	var applyStation = function() {
	 	var items=document.getElementsByName("stationIds");
		var arr=new Array();
		var i=0;
			for(var x=0;x<items.length;x++){
				if(items[x].checked){
					 arr[i] = items[x].value;
					 i++;
					}
				}
		if(arr.length==0||arr.length<0){
			alert("至少选一个");
		}else{ 
			respData ={
			"stationIds":arr,
			"endTime":$("#endTime").val(),	
			"startTime":$("#startTime").val(),	
			"sumRental":$("#sumRental1").val()
			};
			$.post("api/resourecLease/addNewlyLease", respData,function(){
			  	alert('申请工位成功！等待审核');
			  	window.location.href="myworkaddr.jsp";
			});
		}
	}
	//时间插件
		$(function () {
			var currYear = (new Date()).getFullYear();	
			var opt={};
			opt.date = {preset : 'date'};
			opt.datetime = {preset : 'datetime'};
			opt.time = {preset : 'time'};
			opt.default = {
				theme: 'android-ics light', //皮肤样式
				display: 'modal', //显示方式 
				mode: 'scroller', //日期选择模式
				dateFormat: 'yyyy-mm-dd',
				lang: 'zh',
				showNow: true,
				nowText: "今天",
				startYear: currYear, //开始年份
				endYear: currYear + 10 //结束年份
			};
			$("#startTime").mobiscroll($.extend(opt['date'], opt['default']));
		});
		$(function(){
			var reqdata={
					"newlyStatus":"0",
					"status":"1",
					"stationStatus":"2",
				}
				$.post("api/resourecLease/stationImg", reqdata,function(data){
						if(data.code!=0){
							alert(data);
							return;
							}
						var stations=data.response.listS;
						var req=data.response.listAllS;
						if(req.length>0){
							var b=parseInt(req[0].totalLines);
							var a=parseInt(req[0].totalRows);
						$('#table1').empty();
						for(i=0;i<b;i++){
						$('#table1').append("<tr id='tr"+i+"'></tr>");
						for(j=0;j<a;j++){
								if(req[(i*a)+j].state!=0){
											$("#tr"+i).append("<td id= td"+req[(i*a)+j].name+" class='occupy' >"+req[(i*a)+j].name+"</td>");
										}else{
													var f="s"+i+j;
													var val=name+i+j+","+i+","+j;
													$("#tr"+i).append("<td id='td"+f+"'>"+req[(i*a)+j].name+"</td>");
													jQuery("#td"+f).attr('onclick','sumMoney("'+f+'");');
													$("#td"+f).append("<input type='checkbox' id=stationId"+f+" name='stationIds' value="+req[(i*a)+j].stationId+" style='display:none;'>" );
													$("#td"+f).append("<input id='inp"+f+"' value="+req[(i*a)+j].rental+" style='display:none;'>");
													$("#td"+f).append("<input id='status"+f+"' value='0' style='display:none;'>");
													$("#checkbox"+f).attr("value",val);
										}
									}
								}
							}
						});
		});
		//计算价格和
		function sumMoney(value){
			var stat=jQuery("#status"+value).val();
			if(stat==0){
				document.getElementById("td"+value).style.background= "red";
				var rental=document.getElementById("inp"+value).value;
				var b=parseFloat(rental);
				sumRental=b+sumRental;
				document.getElementById("sumRental1").value=sumRental;
				//封装lease数据
				var stationStatus=document.getElementById("stationId"+value);
				stationStatus.checked=true;
				document.getElementById("status"+value).value=1;
				addmulMonth(monthMumber2);
			}else{
				document.getElementById("td"+value).style.background= "#ffffff";
				var rental=document.getElementById("inp"+value).value;
				var b=parseFloat(rental);
				sumRental=sumRental-b;
				document.getElementById("sumRental1").value=sumRental;
				//删除lease数据
				var stationStatus=document.getElementById("stationId"+value);
				stationStatus.checked=false;
				document.getElementById("status"+value).value=0;
				addmulMonth(monthMumber2);
			}
		};
	</script>
	</body>
</html>
